<?php 
require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/acc_conn.php';

function get_user_name_by_loginId($loginId) {
    $pdb = new acc_DB();
    $ssql = "select uName from users where loginId='" . $loginId . "';";

    $fnb = $pdb->qw($ssql, "uName");
    if (null == $fnb){
        return "Not Found!";
    }
    return $fnb;
}

function get_user_id_by_loginId($loginId) {
    $pdb = new acc_DB();
    $ssql = "select id from users where loginId='" . $loginId . "';";

    $fnb = $pdb->qw($ssql, "id");
    if (null == $fnb){
        return "Not Found!";
    }
    return $fnb;
}

function get_saleman_source() { //取得业务员列表
	$pdb = new acc_DB();
	$rst = $pdb->q("select * from users where role_id='10006' order by loginId;");
    $str = '[';

    $chkArr = array(); //重名Check
	while($r = $rst->fetchArray(SQLITE3_ASSOC)) {
        $loginId = $r["loginId"];
        $uName = $r["uName"];
        $id = $r["id"];

        $showName = $uName;
        if(in_array($uName, $chkArr)) {
            $showName = $uName . "(" . $loginId . ")"; //重名时,附加年龄识别 或许好些
        } else {
            array_push($chkArr, $uName);           
        }
        $str .= '{label: "' . $showName . '", value:"' . $showName . '", abbr:"' . $loginId . '", v:' . $id . '},' . "\r\n";
	}
	$pdb->d();
    $str .= "]";
	return $str;
}



?>